﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLLopHoc.DoiTuongDuLieu;
using QLLopHoc.KetNoiDatabase;
using QLLopHoc.XuLyDuLieu;

namespace QLLopHoc
{
    public partial class frmThemLH : DevExpress.XtraEditors.XtraForm
    {
        public frmThemLH()
        {
            InitializeComponent();
        }

        private void frmThemLH_Load(object sender, EventArgs e)
        {
            //lấy danh sách giảng viên 
            List<DTGiangVien> dsgv = XLGiangVien.LayDSGiangVien();
            //đưa dsgv vào combobox 
            cmbGiangVien.Items.Clear();
            cmbGiangVien.Items.AddRange(dsgv.ToArray());
            cmbGiangVien.DisplayMember = "HoTen";
            if (cmbGiangVien.Items.Count > 0)
            {
                cmbGiangVien.SelectedIndex = 0;
            } 
        }
        public DTLopHoc LopHoc
        {
            get
            {
                DTLopHoc lh = new DTLopHoc();
                lh.TenLopHoc = txtTenLH.Text;
                int idx = cmbGiangVien.SelectedIndex;
                if (idx > -1)
                    lh.MaGiangVien = ((DTGiangVien)cmbGiangVien.Items[idx]).MSSV;
                return lh;
            }
        } 

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtTenLH.Text == "" || cmbGiangVien.SelectedIndex == -1)
            {
                MessageBox.Show("Chưa có đủ thông tin.");
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void btnBo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}